use actix_web::{get, HttpResponse, post, Responder, web};

#[get("/")]
async fn hello() -> impl Responder {
    HttpResponse::Ok().body("Hello world!")
}

#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
    println!("123:{req_body:?}");
    HttpResponse::Ok().body(req_body)
}

struct AppState {
    app_name: String,
}

#[get("/test1")]
async fn test1(data: web::Data<AppState>) -> String {
    let app_name = &data.app_name; // <- get app_name
    println!("app_name:{:?}", &data.app_name);
    format!("Hello {app_name}!") // <- response with app_name
}